package com.example.demo.controller;

import com.example.demo.pojo.Message;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    List<Message> list=new ArrayList<>();

    @RequestMapping("/publish")
    //这里应该post请求不行的，不知道为什么
    //但是get请求是可以的
    public boolean publishMessage( Message message) {
        System.out.println(message.getFrom()+" "+message.getTo()+" "+message.getMessage());
        if(!StringUtils.hasLength(message.getFrom()) ||
        !StringUtils.hasLength(message.getTo())||
        !StringUtils.hasLength(message.getMessage())) {
            return false;
        }
        list.add(message);
        return true;
    }
    @RequestMapping("/getList")
    public List<Message> getMessage(Message message) {
        return  list;
    }
}
